﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Practices.EnterpriseLibrary.Data;
using Enterprise.DataFactory;
using Enterprise.Model.Role;
using Enterprise.Infrastructure;
namespace Enterprise.Data.Role
{
    /// <summary>
    /// 角色权限值表操作
    /// </summary>
    public class RolePermissionData
    {
        /// <summary>
        ///  角色权限值数据列表
        /// </summary>
        /// <returns></returns>
        public List<RolePermissionEntity> RolePermissionList()
        {
            List<RolePermissionEntity> list = new List<RolePermissionEntity>();
            string cmd = "Select * from SYS_ROLEPERMISSION";
            IDataReader dr = DbExecute.DataReader(cmd);
            while (dr.Read())
            {
                RolePermissionEntity entity = new RolePermissionEntity();
                if (!Convert.IsDBNull(dr["RPID"])) entity.RPID = Convert.ToInt32(dr["RPID"]);
                if (!Convert.IsDBNull(dr["ROLEID"])) entity.ROLEID = Convert.ToInt32(dr["ROLEID"]);
                if (!Convert.IsDBNull(dr["MODULEID"])) entity.MODULEID = Convert.ToInt32(dr["MODULEID"]);
                if (!Convert.IsDBNull(dr["MCODE"])) entity.MCODE = Convert.ToString(dr["MCODE"]);
                if (!Convert.IsDBNull(dr["PERMISSIONVALUE"])) entity.PERMISSIONVALUE = Convert.ToInt32(dr["PERMISSIONVALUE"]);                
                list.Add(entity);
            }
            dr.Close();
            return list;
        }

        /// <summary>
        /// 角色权限数据操作方法
        /// </summary>
        /// <param name="cmd"></param>
        public void RolePermissionExecute(string cmd)
        {
            DbExecute.Execute(cmd);
        }
    }
}
